<?php

{{ builderInfo.php|raw }}

namespace {{ appNamespace }}\Core;

class Permissions extends \ADIOS\Core\Permissions {
  public function loadPermissions(): array {
    $permissions = parent::loadPermissions();

    $prototypePermissionsByRoleNames =
{{ varExport(permissions, "      ")|raw }}
    ;

    $userRoleModel = $this->app->getCoreClass('Models\\UserRole');
    $idUserRoleByRoleName = array_flip($userRoleModel::USER_ROLES);

    $prototypePermissions = [];
    foreach ($prototypePermissionsByRoleNames as $roleName => $rolePermissions) {
      $prototypePermissions[$idUserRoleByRoleName[$roleName] ?? 0] = $rolePermissions;
    }

    return \ADIOS\Core\Helper::arrayMergeRecursively($permissions, $prototypePermissions);
  }
}
